#include "Drv_Screen.h"
#include "stdio.h"
#include "stdarg.h"
#include "stm32f4xx_hal.h"
#include  "usart.h"
#include "Drv_Uav.h"
int now_x=0,now_y=0;
int wp_n_x=0,wp_n_y=0,wp_2_x=20,wp_2_y=20;
int mileage=100;
int car_flag=0;
void Screen_Data_Send(char *stream, ...)
{
    unsigned char  _data[128];
    char buf[128];
    uint8_t i=0;
    uint8_t _cnt=0;

    va_list ap;
    va_start(ap, stream);
    vsprintf(buf, stream, ap);
    va_end(ap);
    do
    {
        _data[_cnt++]= *(buf+i);
        i++;
        if(_cnt>128)break;
    }
    while(*(buf+i)!='\0');
    for (int j = 0; j < _cnt; j++)
    {
        HAL_UART_Transmit(&huart5, (uint8_t *)_data+j, 1, 100);//给串口屏
        //HAL_UART_Transmit(&huart1, (uint8_t *)_data+j, 1, 100);//给串口屏
    }
    //print_UARTx(&huart5,_data);
    //SCREEN_PUT_BUFF(_data, strlen(buf));
}
void Screen_task()
{
    char s[15];
    Screen_Data_Send("cirs %d,%d,%d,%s\xff\xff\xff",now_x,now_y,5,"BLUE");
   // if(wp_n_x!=wp_2_x&&wp_n_y!=wp_2_y)
      //  Screen_Data_Send("line %d,%d,%d,%d,%s\xff\xff\xff",wp_n_x+100,240-wp_n_y,wp_2_x+100,240-wp_2_y,"GREEN");
    //里程显示
    Screen_Data_Send("%s%d\xff\xff\xff","map.x0.val=",mileage*100);
    //print_UARTx(&huart5, "%s%d\xff\xff\xff","map.x0.val=",mileage*100);
    //状态显示
    //sprintf(s,"\"%s\"",car_flag==1?"已完成":"未完成");

    Screen_Data_Send("%s\"%s\"\xff\xff\xff","map.t5.txt=",car_flag==1?"open":"close");
    //坐标显示
    Screen_Data_Send("%s\"(%d,%d)\"\xff\xff\xff","map.t8.txt=", wp_n_x,wp_n_y);


}
extern int start_mission;
void Screen_DataAnl(uint8_t *data)
{
    if(data[0]==0x3f&&data[2]==0xff&&data[3]==0xff)
    {
        switch(data[1])
        {
            case CAR_START:
            {
                start_mission=1;
                break;
            }
            case UAV_START:
            {
                Uav_DataSend(data);
                break;
            }
        }
    }
    print_UARTx(&huart1,data);
}

